package com.njl.controller;

import java.util.List;

import org.apache.log4j.Logger;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;

import com.njl.entity.OrdinaryUsers;
import com.njl.entity.User;
import com.njl.service.UsersService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.syb.entity.user.SysUser;
import com.syb.util.PageResults;

@Namespace("/frontUser")
public class UserController extends ActionSupport{
	Logger logger = Logger.getLogger(UserController.class);
	@Autowired
	private UsersService userService;
	private PageResults<SysUser> page;
	private List<OrdinaryUsers> ordinaryUserList;
	private OrdinaryUsers ordinaryUsers;
	private User user;
	public Logger getLogger() {
		return logger;
	}


	public void setLogger(Logger logger) {
		this.logger = logger;
	}


	public UsersService getUserService() {
		return userService;
	}


	public void setUserService(UsersService userService) {
		this.userService = userService;
	}


	public OrdinaryUsers getOrdinaryUsers() {
		return ordinaryUsers;
	}


	public void setOrdinaryUsers(OrdinaryUsers ordinaryUsers) {
		this.ordinaryUsers = ordinaryUsers;
	}


	public User getUser() {
		return user;
	}


	public void setUser(User user) {
		this.user = user;
	}


	private Integer currentPage;
	
	@Action(value="saveRegister",
			results={
			@Result(name="success",location="/WEB-INF/page/foreground/index.jsp"),
			@Result(name="error",location="/WEB-INF/fail.jsp")
			})
	public String saveRegister(){
		try{
			System.out.println("scueess");
			System.out.println(user.getUserName());
			userService.registerUser(user);
			System.out.println("user保存成功");
		}catch(Exception e){
			logger.error(e.getMessage());
			ActionContext.getContext().put("error","查询出错！");
			return "error";
		}
		return "success";
	}
	

	public Integer getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(Integer currentPage) {
		this.currentPage = currentPage;
	}


	public PageResults<SysUser> getPage() {
		return page;
	}


	public void setPage(PageResults<SysUser> page) {
		this.page = page;
	}


	public List<OrdinaryUsers> getOrdinaryUserList() {
		return ordinaryUserList;
	}


	public void setOrdinaryUserList(List<OrdinaryUsers> ordinaryUserList) {
		this.ordinaryUserList = ordinaryUserList;
	}
	
	
}
